﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AbingtonBooks.Pages.Profile.Edit
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Customer"] == null)
            {
                Response.Redirect("~/Pages/UnauthorizedAccess");
            }
            else {
                Customer customer = (Customer)Session["Customer"];
                txtFname.Text = customer.FirstName;
                txtLname.Text = customer.LastName;
                txtAddress.Text = customer.Address;
                txtCity.Text = customer.City;
                txtState.Text = customer.State;
                txtZip.Text = customer.ZipCode;
            }

        }

        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            Customer customer = (Customer)Session["Customer"];
            using (dbAbingtonBooks context = new dbAbingtonBooks()) {
                Customer thisCustomer = context.Customers.Where(c => c.CustomerId == customer.CustomerId).First();
                thisCustomer.FirstName = txtFname.Text;
                thisCustomer.LastName = txtLname.Text;
                thisCustomer.Address = txtAddress.Text;
                thisCustomer.City = txtCity.Text;
                thisCustomer.State = txtState.Text.ToUpper();
                thisCustomer.ZipCode = txtZip.Text;

            }

        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Pages/Profile");
        }
    }
}